using System;
using System.Collections.Generic;
using System.Text;
using EnvDTE;
using Microsoft.Practices.RecipeFramework;
using System.Collections;
using Microsoft.Practices.RecipeFramework.Extensions.CommonHelpers;
using Microsoft.Practices.RepositoryFactory.CodeGeneration.ObjectModel;
using Microsoft.Practices.RepositoryFactory.CommonHelpers;

namespace Microsoft.Practices.RepositoryFactory.Actions.VisualStudio
{
    public class CreateEntitiesFoldersAction : ConfigurableAction
    {
        private ArrayList entities;
        private Project project;
        private string dataAccessClassNamespace;
        private string businessEntityClassNamespace;

        [Input(Required = true)]
        public ArrayList Entities
        {
            get 
            { 
                return entities; 
            }
            set 
            { 
                entities = value; 
            }
        }

        [Input(Required = true)]
        public string DataAccessClassNamespace
        {
            get
            {
                return dataAccessClassNamespace;
            }
            set
            {
                dataAccessClassNamespace = value;
            }
        }

        [Input(Required = true)]
        public string BusinessEntityClassNamespace
        {
            get
            {
                return businessEntityClassNamespace;
            }
            set
            {
                businessEntityClassNamespace = value;
            }
        }


        /// <summary>
        /// Gets or sets the project.
        /// </summary>
        /// <value>The project.</value>
        [Input(Required = true)]
        public Project Project
        {
            get { return project; }
            set { project = value; }
        }

        /// <summary>
        /// Executes this instance.
        /// </summary>
        public override void Execute()
        {
            foreach (Entity entity in entities)
            {
                string folderName = NameResolver.ResolveFolderName(entity.Name);

                ProjectItem folder = DteHelperEx.FindItemByName(project.ProjectItems, folderName, true);

                if (folder == null)
                {
                    project.ProjectItems.AddFolder(folderName, String.Empty);
                }
            }
        }

        /// <summary>
        /// Undoes this instance.
        /// </summary>
        public override void Undo()
        {
            //Not Implemented
        }
    }
}
